package com.cn.hangyun.controller;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cn.hangyun.model.Rt_accelration_transducer;
import com.cn.hangyun.model.Rt_currentspeed_control;
import com.cn.hangyun.model.Rt_currentspeed_transducer;
import com.cn.hangyun.model.Rt_waveheight_control;
import com.cn.hangyun.model.Rt_waveheight_transducer;
import com.cn.hangyun.service.IModelService;
import com.cn.hangyun.service.IPoseService;


@Controller
@RequestMapping("/pose")
public class PoseController {

	@Autowired
	private IPoseService poseService;

	@RequestMapping("/waveTrans")
	@ResponseBody
	public List<Rt_waveheight_transducer> getWaveTrans() {
		
		List<Rt_waveheight_transducer> list = poseService.getWaveHeightTransducer();
		return list;
		
	}
	
	@RequestMapping("/waveControl")
	@ResponseBody
	public Rt_waveheight_control getAccControl(Date current) {
		
		Rt_waveheight_control result = poseService.getWaveHeightControl(current);
		return result;
		
	}
	
	@RequestMapping("/getChartData")
	@ResponseBody
	public Object getWaveChartData(String controlId, Date start, 
			int interval, @RequestParam(value = "trans") String trans) {
		
		//get wave data
		 Calendar c = Calendar.getInstance();  
	     c.setTime(start);
	     c.add(Calendar.SECOND, 1);
	     Date end = c.getTime();
		List<String> list = poseService.getWaveHeightData(controlId, start, end, trans);
		List<String> xlist=new ArrayList<String>();
		for (int i=0;i<list.size();i++) {
			xlist.add(String.valueOf(i));
		}
		Map mpRes = new HashMap();
		mpRes.put("xdata", xlist.toArray());
		mpRes.put("ydata", list.toArray());
		
		return mpRes;
		
	}
	
    //流速传感器
	@RequestMapping("/currentSpeedTrans")
	@ResponseBody
	public List<Rt_currentspeed_transducer> getCurrentSpeedTrans() {
		
		List<Rt_currentspeed_transducer> list = poseService.getCurrentSpeedTransducer();
		return list;
		
	}
	@RequestMapping("/currentSpeedControl")
	@ResponseBody
	public Rt_currentspeed_control getCurrentSpeedControl(Date current) {
		
		Rt_currentspeed_control result = poseService.getCurrentSpeedControl(current);
		return result;
		
	}
	
	@RequestMapping("/getCurrentSpeedData")
	@ResponseBody
	public Object getCurrentSpeedData(String controlId, Date start, 
			int interval, @RequestParam(value = "trans") String trans) {
		
		//get wave data
		 Calendar c = Calendar.getInstance();  
	     c.setTime(start);
	     c.add(Calendar.SECOND, 1);
	     Date end = c.getTime();
		List<String> list = poseService.getCurrentSpeedData(controlId, start, end, trans);
		List<String> xlist=new ArrayList<String>();
		for (int i=0;i<list.size();i++) {
			xlist.add(String.valueOf(i));
		}
		Map mpRes = new HashMap();
		mpRes.put("xsdata", xlist.toArray());
		mpRes.put("ysdata", list.toArray());
		
		return mpRes;
		
	}
	
	
	//加速度传感器
	@Autowired
	private IModelService modelService;

	@RequestMapping("/accTrans")
	@ResponseBody
	public Object[] getAccTranas() {
		
		List<Rt_accelration_transducer> list = modelService.getAllAccTran();
		return list.toArray();
		
	}
	
	
}
